﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace thinger.VisionControlLib
{
    public partial class UCPipe : UserControl
    {
        Timer m_timer;//定时器
        /// <summary>
        /// 管道的粗细
        /// </summary>
        int intPenWidth = 0;

        /// <summary>
        ///线左边坐标
        /// </summary>
        int intLineLeft = 0;
        public UCPipe()
        {
            InitializeComponent();
            this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            this.SetStyle(ControlStyles.DoubleBuffer, true);
            this.SetStyle(ControlStyles.ResizeRedraw, true);
            this.SetStyle(ControlStyles.Selectable, true);
            this.SetStyle(ControlStyles.SupportsTransparentBackColor, true);
            this.SetStyle(ControlStyles.UserPaint, true);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None;
            this.SizeChanged += UCPipe_SizeChanged;
            this.Size = new Size(200, 50);
            m_timer = new Timer();
            m_timer.Interval = 100;
            m_timer.Tick += timer_Tick;
        }

        private void timer_Tick(object sender, EventArgs e)
        {
            intLineLeft += 2;
            if (intLineLeft > 12)
                intLineLeft = 0;
            Refresh();

        }

        private void UCPipe_SizeChanged(object sender, EventArgs e)
        {
            intPenWidth = pipeStyle.ToString().StartsWith("H") ? this.Height : this.Width;
        }

        private bool isFlow = false;
        [Description("是否流动"), Category("自定义")]
        public bool IsFlow
        {
            get { return isFlow; }
            set
            {
                isFlow = value;
                if (isFlow)
                {
                    m_timer.Start();
                }
                else
                {
                    m_timer.Stop();
                }
                Refresh();
            }
        }

        private int flowWidth = 4;
        [Description("流动线的粗细"), Category("自定义")]
        public int FlowWidth
        {
            get { return flowWidth; }
            set
            {
                flowWidth = value;
                if (FlowWidth <= 0)
                    return;
                Refresh();
            }
        }

        private int flowLength = 10;
        [Description("流动线的长度"), Category("自定义")]
        public int FlowLength
        {
            get { return flowLength; }
            set
            {
                flowLength = value;
                Refresh();
            }
        }

        private int flowSpace = 4;
        [Description("流动线的间隔"), Category("自定义")]
        public int FlowSpace
        {
            get { return flowSpace; }
            set
            {
                flowSpace = value;
                Refresh();
            }
        }


        /// <summary>
        /// 管道样式
        /// </summary>
        private PipeStyle pipeStyle = PipeStyle.Horizontal_None_None;
        [Description("样式"), Category("自定义")]
        public PipeStyle PipeStyle
        {
            get { return pipeStyle; }
            set
            {
                string strOld = pipeStyle.ToString().Substring(0, 1);
                string strNew = value.ToString().Substring(0, 1);
                pipeStyle = value;
                if (strOld != strNew)
                {
                    this.Size = new Size(this.Size.Height, this.Size.Width);
                }
                Refresh();
            }
        }

        /// <summary>
        /// 管道颜色
        /// </summary>
        private Color pipeColor = Color.FromArgb(255, 77, 59);
        [Description("颜色"), Category("自定义")]
        public Color PipeColor
        {
            get { return pipeColor; }
            set
            {
                pipeColor = value;
                Refresh();
            }
        }

        /// <summary>
        /// 流动条颜色
        /// </summary>
        private Color flowColor = Color.FromArgb(3, 169, 243);
        [Description("液体颜色"), Category("自定义")]
        public Color FlowColor
        {
            get { return flowColor; }
            set
            {
                flowColor = value;
                if (flowDirection != FlowDirection.None)
                    Refresh();
            }
        }

        /// <summary>
        ///流动方向
        /// </summary>
        private FlowDirection flowDirection = FlowDirection.Forward;

        [Description("流动方向"), Category("自定义")]
        public FlowDirection FlowDirection
        {
            get { return flowDirection; }
            set
            {
                flowDirection = value;
                Refresh();
            }
        }

        /// <summary>
        /// 流动速度 定时器间隔
        /// </summary>
        private int flowSpeed = 100;
        [Description("流速，越小，速度越快"), Category("自定义")]
        public int FlowSpeed
        {
            get { return flowSpeed; }
            set
            {
                if (value <= 0)
                    return;
                flowSpeed = value;
                m_timer.Interval = value;
            }
        }



        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            Graphics g = e.Graphics;
            g.SmoothingMode = SmoothingMode.AntiAlias;
            //圆弧线集合
            List<ArcClass> lstArcs = new List<ArcClass>();
            //外轮廓路径
            GraphicsPath path = new GraphicsPath();
            //线路径
            GraphicsPath linePath = new GraphicsPath();
            switch (PipeStyle)
            {
                #region 
                case PipeStyle.Horizontal_None_None://水平
                    path.AddLines(new PointF[]
                    {
                        new PointF(0, 0),//左上角点
                        new PointF(this.ClientRectangle.Right, 0),//右上角点
                        new PointF(this.ClientRectangle.Right, this.Height),//右下角点
                        new PointF(0, this.Height)//左下角点
                    });
                    path.CloseAllFigures();//闭合
                    //添加一条水平线到linePath中  （中间流动线）
                    linePath.AddLine(0, this.Height / 2, this.Width, this.Height / 2);
                    break;
                case PipeStyle.Horizontal_Up_None://水平左上弯
                    path.AddLines(new PointF[]
                    {
                        new PointF(0, 0),
                        new PointF(this.ClientRectangle.Right, 0),
                        new PointF(this.ClientRectangle.Right, this.Height),
                        new PointF(0+intPenWidth, this.Height)//左下角点  下边直线弯道前的点 
                    });
                    //添加上弯弧线  所在圆的矩形左上角y：intPenWidth * -1
                    path.AddArc(new Rectangle(0, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), 90, 90);
                    path.CloseAllFigures();//闭合
                    //添加中间流动线  左边圆弧+右边直线
                    linePath.AddArc(new Rectangle(intPenWidth / 2 + 1, -1 * intPenWidth / 2 - 1, intPenWidth, intPenWidth), 181, -91);
                    //右边直线
                    linePath.AddLine(intPenWidth, this.Height / 2, this.Width, this.Height / 2);
                    //添加圆弧，左下角圆弧
                    lstArcs.Add(new ArcClass() { rect = new Rectangle(0, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), startAngle = 90, sweepAngle = 90 });
                    break;
                case PipeStyle.Horizontal_Down_None://水平左下弯
                    path.AddLines(new PointF[]
                    {
                        new PointF(intPenWidth, 0),//上边横线的起点
                        new PointF(this.ClientRectangle.Right, 0),//右上角点
                        new PointF(this.ClientRectangle.Right, this.Height),//右下角点
                        new PointF(0, this.Height)//左下角点
                    });
                    //左上角圆弧  向上旋转90度
                    path.AddArc(new Rectangle(0, 0, intPenWidth * 2, intPenWidth * 2), 180, 90);
                    path.CloseAllFigures();//闭合
                    //添加流动线向上旋转弧
                    linePath.AddArc(new Rectangle(intPenWidth / 2 + 1, this.Height / 2, intPenWidth, intPenWidth), 179, 91);
                    //流动线 向右直线
                    linePath.AddLine(intPenWidth + 1, this.Height / 2, this.Width, this.Height / 2);
                    //添加圆弧到集合中
                    lstArcs.Add(new ArcClass() { rect = new Rectangle(0, -1, intPenWidth * 2, intPenWidth * 2), startAngle = 180, sweepAngle = 90 });
                    break;
                case PipeStyle.Horizontal_None_Up://水平右上弯
                    path.AddLines(new PointF[]
                    {
                        //右下角直线起点（右边就是向下旋转弧）
                        new PointF(this.ClientRectangle.Right-intPenWidth, this.Height),
                        //左下角点
                        new PointF(0, this.Height),
                        //左上角点
                        new PointF(0, 0),
                        //右上角点
                        new PointF(this.ClientRectangle.Right, 0)
                    });
                    //添加右下角弧线
                    path.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), 0, 90);
                    path.CloseAllFigures();
                    //添加中间流动线
                    linePath.AddLine(0, this.Height / 2, this.Width - intPenWidth, this.Height / 2);
                    linePath.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth - intPenWidth / 2 - 1, -1 * intPenWidth / 2 - 1, intPenWidth, intPenWidth), 91, -91);
                    //添加右下角圆弧
                    lstArcs.Add(new ArcClass() { rect = new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), startAngle = 0, sweepAngle = 90 });
                    break;
                case PipeStyle.Horizontal_None_Down://水平右下弯
                    path.AddLines(new PointF[]
                    {
                        new PointF(this.ClientRectangle.Right, this.Height),//右下角点
                        new PointF(0, this.Height),//右下角点
                        new PointF(0, 0),//左上角点
                        new PointF(this.ClientRectangle.Right-intPenWidth, 0)//右上角点（右边是向下圆弧）
                    });
                    //添加右上角弧线
                    path.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, -1, intPenWidth * 2, intPenWidth * 2), 270, 90);
                    path.CloseAllFigures();
                    //添加流动线+弧线
                    linePath.AddLine(0, this.Height / 2, this.Width - intPenWidth - 1, this.Height / 2);
                    linePath.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth - intPenWidth / 2 - 1, intPenWidth / 2, intPenWidth, intPenWidth), 269, 91);
                    //添加向下弧线
                    lstArcs.Add(new ArcClass() { rect = new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, -1, intPenWidth * 2, intPenWidth * 2), startAngle = 270, sweepAngle = 90 });
                    break;
                case PipeStyle.Horizontal_Down_Up://水平左下右上
                    //添加上边直线（去掉弧线部分）
                    path.AddLine(new Point(intPenWidth, 0), new Point(this.Width, 0));
                    //添加右下角弧线
                    path.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), 0, 90);
                    //添加下线直线
                    path.AddLine(new Point(this.Width - intPenWidth, this.Height), new Point(0, this.Height));
                    //添加左上角弧线
                    path.AddArc(new Rectangle(0, 0, intPenWidth * 2, intPenWidth * 2), 180, 90);
                    path.CloseAllFigures();
                    //添加流动线圆弧 左上
                    linePath.AddArc(new Rectangle(intPenWidth / 2 + 1, this.Height / 2, intPenWidth, intPenWidth), 179, 91);
                    //添加流动线圆弧 右下
                    linePath.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth - intPenWidth / 2 - 1, -1 * intPenWidth / 2 - 1, intPenWidth, intPenWidth), 91, -91);
                    //添加左上  右下圆弧
                    lstArcs.Add(new ArcClass() { rect = new Rectangle(0, -1, intPenWidth * 2, intPenWidth * 2), startAngle = 180, sweepAngle = 90 });
                    lstArcs.Add(new ArcClass() { rect = new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), startAngle = 0, sweepAngle = 90 });
                    break;
                case PipeStyle.Horizontal_Up_Down://左上右下
                    //添加上直线
                    path.AddLine(new Point(0, 0), new Point(this.Width - intPenWidth, 0));
                    //右上圆弧
                    path.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, -1, intPenWidth * 2, intPenWidth * 2), 270, 90);
                    //添加下直线
                    path.AddLine(new Point(this.Width, this.Height), new Point(intPenWidth, this.Height));
                    //添加左下圆弧
                    path.AddArc(new Rectangle(0, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), 90, 90);
                    path.CloseAllFigures();
                    //流动线 添加圆弧 左上
                    linePath.AddArc(new Rectangle(intPenWidth / 2 + 1, -1 * intPenWidth / 2 - 1, intPenWidth, intPenWidth), 181, -91);
                    //流动线 中间直接
                    linePath.AddLine(intPenWidth, this.Height / 2, this.Width - intPenWidth - 1, this.Height / 2);
                    //流动线 右下圆弧
                    linePath.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth - intPenWidth / 2 - 1, intPenWidth / 2, intPenWidth, intPenWidth), 269, 91);
                    //添加左下  右上圆弧
                    lstArcs.Add(new ArcClass() { rect = new Rectangle(0, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), startAngle = 90, sweepAngle = 90 });
                    lstArcs.Add(new ArcClass() { rect = new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, -1, intPenWidth * 2, intPenWidth * 2), startAngle = 270, sweepAngle = 90 });
                    break;
                case PipeStyle.Horizontal_Up_Up://左上右上
                    //上边直线
                    path.AddLine(new Point(0, 0), new Point(this.Width, 0));
                    //右下圆弧
                    path.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), 0, 90);
                    //下边直线
                    path.AddLine(new Point(this.Width - intPenWidth, this.Height), new Point(intPenWidth, this.Height));
                    //左上圆弧
                    path.AddArc(new Rectangle(0, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), 90, 90);
                    path.CloseAllFigures();
                    //添加流动线右下圆弧
                    linePath.AddArc(new Rectangle(intPenWidth / 2 + 1, -1 * intPenWidth / 2 - 1, intPenWidth, intPenWidth), 181, -91);
                    //添加流动线左下圆弧
                    linePath.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth - intPenWidth / 2 - 1, -1 * intPenWidth / 2 - 1, intPenWidth, intPenWidth), 91, -91);
                    //添加左下圆弧
                    lstArcs.Add(new ArcClass() { rect = new Rectangle(0, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), startAngle = 90, sweepAngle = 90 });
                    //添加右下圆弧 
                    lstArcs.Add(new ArcClass() { rect = new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, intPenWidth * -1, intPenWidth * 2, intPenWidth * 2), startAngle = 0, sweepAngle = 90 });
                    break;
                case PipeStyle.Horizontal_Down_Down://水平左下右下
                    //上边直线
                    path.AddLine(new Point(intPenWidth, 0), new Point(this.Width - intPenWidth, 0));
                    //右上角圆弧
                    path.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, -1, intPenWidth * 2, intPenWidth * 2), 270, 90);
                    //下边线
                    path.AddLine(new Point(this.Width, this.Height), new Point(0, this.Height));
                    //左上角圆弧
                    path.AddArc(new Rectangle(0, -1, intPenWidth * 2, intPenWidth * 2), 180, 90);
                    path.CloseAllFigures();
                    //添加流动线 左上角圆弧
                    linePath.AddArc(new Rectangle(intPenWidth / 2 + 1, this.Height / 2, intPenWidth, intPenWidth), 179, 91);
                    //中间直线
                    linePath.AddLine(intPenWidth + 1, this.Height / 2, this.Width - intPenWidth - 1, this.Height / 2);
                    //右上角圆弧
                    linePath.AddArc(new Rectangle(this.ClientRectangle.Right - intPenWidth - intPenWidth / 2 - 1, intPenWidth / 2, intPenWidth, intPenWidth), 269, 91);
                    //添加 左上角  右上角圆弧
                    lstArcs.Add(new ArcClass() { rect = new Rectangle(0, -1, intPenWidth * 2, intPenWidth * 2), startAngle = 180, sweepAngle = 90 });
                    lstArcs.Add(new ArcClass() { rect = new Rectangle(this.ClientRectangle.Right - intPenWidth * 2, -1, intPenWidth * 2, intPenWidth * 2), startAngle = 270, sweepAngle = 90 });
                    break;
                #endregion

                #region 
                case PipeStyle.Vertical_None_None:
                    path.AddLines(new PointF[]
                    {
                        new PointF(0, 0),
                        new PointF(this.ClientRectangle.Right, 0),
                        new PointF(this.ClientRectangle.Right, this.Height),
                        new PointF(0, this.Height)
                    });
                    path.CloseAllFigures();
                    linePath.AddLine(this.Width / 2, 0, this.Width / 2, this.Height);
                    break;
                case PipeStyle.Vertical_Left_None:
                    path.AddLines(new PointF[]
                    {
                        new PointF(this.ClientRectangle.Right, intPenWidth),
                        new PointF(this.ClientRectangle.Right, this.Height),
                        new PointF(0, this.Height),
                        new PointF(0, 0)
                    });
                    path.AddArc(new Rectangle(-1 * intPenWidth, 0, intPenWidth * 2, intPenWidth * 2), 270, 90);
                    path.CloseAllFigures();

                    linePath.AddArc(new Rectangle(-1 * intPenWidth / 2 - 1, intPenWidth / 2 + 1, intPenWidth, intPenWidth), 269, 91);
                    linePath.AddLine(intPenWidth / 2, intPenWidth, intPenWidth / 2, this.Height);

                    lstArcs.Add(new ArcClass() { rect = new Rectangle(-1 * intPenWidth, 0, intPenWidth * 2, intPenWidth * 2), startAngle = 270, sweepAngle = 90 });
                    break;
                case PipeStyle.Vertical_Right_None:
                    path.AddLines(new PointF[]
                    {
                        new PointF(this.ClientRectangle.Right, 0),
                        new PointF(this.ClientRectangle.Right, this.Height),
                        new PointF(0, this.Height),
                        new PointF(0, intPenWidth)
                    });
                    path.AddArc(new Rectangle(-1, 0, intPenWidth * 2, intPenWidth * 2), 180, 90);
                    path.CloseAllFigures();

                    linePath.AddArc(new Rectangle(intPenWidth / 2, intPenWidth / 2 + 1, intPenWidth, intPenWidth), 271, -91);
                    linePath.AddLine(intPenWidth / 2, intPenWidth + 1, intPenWidth / 2, this.Height);

                    lstArcs.Add(new ArcClass() { rect = new Rectangle(-1, 0, intPenWidth * 2, intPenWidth * 2), startAngle = 180, sweepAngle = 90 });
                    break;
                case PipeStyle.Vertical_None_Left:
                    path.AddLines(new PointF[]
                    {
                        new PointF(0, this.Height),
                        new PointF(0, 0),
                        new PointF(this.ClientRectangle.Right, 0),
                        new PointF(this.ClientRectangle.Right, this.Height-intPenWidth),
                    });
                    path.AddArc(new Rectangle(-1 * intPenWidth, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), 0, 90);
                    path.CloseAllFigures();

                    linePath.AddLine(this.Width / 2, 0, this.Width / 2, this.Height - intPenWidth);
                    linePath.AddArc(new Rectangle(-1 * intPenWidth / 2 - 1, this.Height - intPenWidth - intPenWidth / 2 - 1, intPenWidth, intPenWidth), -1, 91);

                    lstArcs.Add(new ArcClass() { rect = new Rectangle(-1 * intPenWidth, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), startAngle = 0, sweepAngle = 90 });
                    break;
                case PipeStyle.Vertical_None_Right:
                    path.AddLines(new PointF[]
                    {
                        new PointF(0, this.Height-intPenWidth),
                        new PointF(0, 0),
                        new PointF(this.ClientRectangle.Right, 0),
                        new PointF(this.ClientRectangle.Right, this.Height),
                    });
                    path.AddArc(new Rectangle(-1, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), 90, 90);
                    path.CloseAllFigures();

                    linePath.AddLine(this.Width / 2, 0, this.Width / 2, this.Height - intPenWidth - 1);
                    linePath.AddArc(new Rectangle(intPenWidth / 2, this.Height - intPenWidth - intPenWidth / 2 - 1, intPenWidth, intPenWidth), 181, -91);

                    lstArcs.Add(new ArcClass() { rect = new Rectangle(-1, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), startAngle = 90, sweepAngle = 90 });
                    break;
                case PipeStyle.Vertical_Left_Right:
                    path.AddLine(this.Width, intPenWidth, this.Width, this.Height);
                    path.AddArc(new Rectangle(-1, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), 90, 90);
                    path.AddLine(0, this.Height - intPenWidth, 0, 0);
                    path.AddArc(new Rectangle(-1 * intPenWidth, 0, intPenWidth * 2, intPenWidth * 2), 270, 90);
                    path.CloseAllFigures();

                    linePath.AddArc(new Rectangle(-1 * intPenWidth / 2 - 1, intPenWidth / 2 + 1, intPenWidth, intPenWidth), 269, 91);
                    linePath.AddArc(new Rectangle(intPenWidth / 2, this.Height - intPenWidth - intPenWidth / 2 - 1, intPenWidth, intPenWidth), 181, -91);

                    lstArcs.Add(new ArcClass() { rect = new Rectangle(-1 * intPenWidth, 0, intPenWidth * 2, intPenWidth * 2), startAngle = 270, sweepAngle = 90 });
                    lstArcs.Add(new ArcClass() { rect = new Rectangle(-1, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), startAngle = 90, sweepAngle = 90 });
                    break;
                case PipeStyle.Vertical_Right_Left:
                    path.AddLine(this.Width, 0, this.Width, this.Height - intPenWidth);
                    path.AddArc(new Rectangle(-1 * intPenWidth, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), 0, 90);
                    path.AddLine(0, this.Height, 0, intPenWidth);
                    path.AddArc(new Rectangle(-1, 0, intPenWidth * 2, intPenWidth * 2), 180, 90);
                    path.CloseAllFigures();

                    linePath.AddArc(new Rectangle(intPenWidth / 2, intPenWidth / 2 + 1, intPenWidth, intPenWidth), 271, -91);
                    linePath.AddArc(new Rectangle(-1 * intPenWidth / 2 - 1, this.Height - intPenWidth - intPenWidth / 2 - 1, intPenWidth, intPenWidth), -1, 91);

                    lstArcs.Add(new ArcClass() { rect = new Rectangle(-1, 0, intPenWidth * 2, intPenWidth * 2), startAngle = 180, sweepAngle = 90 });
                    lstArcs.Add(new ArcClass() { rect = new Rectangle(-1 * intPenWidth, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), startAngle = 0, sweepAngle = 90 });
                    break;
                case PipeStyle.Vertical_Left_Left:
                    path.AddLine(this.Width, intPenWidth, this.Width, this.Height - intPenWidth);
                    path.AddArc(new Rectangle(-1 * intPenWidth, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), 0, 90);
                    path.AddLine(0, this.Height, 0, 0);
                    path.AddArc(new Rectangle(-1 * intPenWidth, 0, intPenWidth * 2, intPenWidth * 2), 270, 90);
                    path.CloseAllFigures();

                    linePath.AddArc(new Rectangle(-1 * intPenWidth / 2 - 1, intPenWidth / 2 + 1, intPenWidth, intPenWidth), 269, 91);
                    linePath.AddArc(new Rectangle(-1 * intPenWidth / 2 - 1, this.Height - intPenWidth - intPenWidth / 2 - 1, intPenWidth, intPenWidth), -1, 91);

                    lstArcs.Add(new ArcClass() { rect = new Rectangle(-1 * intPenWidth, 0, intPenWidth * 2, intPenWidth * 2), startAngle = 270, sweepAngle = 90 });
                    lstArcs.Add(new ArcClass() { rect = new Rectangle(-1 * intPenWidth, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), startAngle = 0, sweepAngle = 90 });
                    break;
                case PipeStyle.Vertical_Right_Right:
                    path.AddLine(this.Width, 0, this.Width, this.Height);
                    path.AddArc(new Rectangle(-1, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), 90, 90);
                    path.AddLine(0, this.Height - intPenWidth, 0, intPenWidth);
                    path.AddArc(new Rectangle(-1, 0, intPenWidth * 2, intPenWidth * 2), 180, 90);
                    path.CloseAllFigures();

                    linePath.AddArc(new Rectangle(intPenWidth / 2, intPenWidth / 2 + 1, intPenWidth, intPenWidth), 271, -91);
                    linePath.AddArc(new Rectangle(intPenWidth / 2, this.Height - intPenWidth - intPenWidth / 2 - 1, intPenWidth, intPenWidth), 180, -91);

                    lstArcs.Add(new ArcClass() { rect = new Rectangle(-1, 0, intPenWidth * 2, intPenWidth * 2), startAngle = 180, sweepAngle = 90 });
                    lstArcs.Add(new ArcClass() { rect = new Rectangle(-1, this.Height - intPenWidth * 2, intPenWidth * 2, intPenWidth * 2), startAngle = 90, sweepAngle = 90 });
                    break;
                    #endregion
            }
            //填充管道颜色
            g.FillPath(new SolidBrush(PipeColor), path);

            //渐变色
            int intCount = intPenWidth / 2 / 4;
            int intSplit = (255 - 100) / intCount;
            for (int i = 0; i < intCount; i++)
            {
                int _penWidth = intPenWidth / 2 - 4 * i;
                if (_penWidth <= 0)
                    _penWidth = 1;
                //画流动线外围的渐变色（浅白部分）
                g.DrawPath(new Pen(new SolidBrush(Color.FromArgb(40, Color.White.R, Color.White.G, Color.White.B)), _penWidth), linePath);
                if (_penWidth == 1)
                    break;
            }

            //液体流动
            if (FlowDirection != FlowDirection.None)
            {
                Pen p = new Pen(new SolidBrush(FlowColor), FlowWidth);
                //虚线的样式
                p.DashPattern = new float[] { FlowLength, FlowSpace };
                p.DashOffset = intLineLeft * (FlowDirection == FlowDirection.Forward ? -1 : 1);
                //变中心流动线
                g.DrawPath(p, linePath);
            }
        }
    }



    /// <summary>
    /// 圆角类
    /// </summary>
    class ArcClass
    {
        /// <summary>
        /// 矩形区域
        /// </summary>
        public Rectangle rect { get; set; }
        /// <summary>
        ///开始角度
        /// </summary>
        public float startAngle { get; set; }
        /// <summary>
        /// 转动角度
        /// </summary>
        public float sweepAngle { get; set; }
    }


    /// <summary>
    /// 流动方向
    /// </summary>
    public enum FlowDirection
    {
        None,
        /// <summary>
        /// 向后
        /// </summary>
        Forward,
        /// <summary>
        /// 向前
        /// </summary>
        Backward
    }

    /// <summary>
    /// 管道样式
    /// </summary>
    public enum PipeStyle
    {
        /// <summary>
        /// 直线 
        /// </summary>
        Horizontal_None_None,
        /// <summary>
        /// 左上
        /// </summary>
        Horizontal_Up_None,
        /// <summary>
        /// 左下
        /// </summary>
        Horizontal_Down_None,
        /// <summary>
        /// 右上
        /// </summary>
        Horizontal_None_Up,
        /// <summary>
        /// 右下
        /// </summary>
        Horizontal_None_Down,
        /// <summary>
        /// 左下右上
        /// </summary>
        Horizontal_Down_Up,
        /// <summary>
        /// 左上右下
        /// </summary>
        Horizontal_Up_Down,
        /// <summary>
        /// 左上，右上
        /// </summary>
        Horizontal_Up_Up,
        /// <summary>
        /// 左下右下
        /// </summary>
        Horizontal_Down_Down,

        /// <summary>
        /// 竖线
        /// </summary>
        Vertical_None_None,
        /// <summary>
        /// 上左
        /// </summary>
        Vertical_Left_None,
        /// <summary>
        /// 上右
        /// </summary>
        Vertical_Right_None,
        /// <summary>
        /// 下左
        /// </summary>
        Vertical_None_Left,
        /// <summary>
        /// 下右
        /// </summary>
        Vertical_None_Right,
        /// <summary>
        /// 上左下右
        /// </summary>
        Vertical_Left_Right,
        /// <summary>
        /// 上右下左
        /// </summary>
        Vertical_Right_Left,
        /// <summary>
        /// 上左下左
        /// </summary>
        Vertical_Left_Left,
        /// <summary>
        /// 上右下右
        /// </summary>
        Vertical_Right_Right,
    }
}
